﻿using Api.Application.Command.Role;
using Api.Application.Command.User;
using Api.DTO;
using ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;

namespace Api.Controllers
{
    /// <summary>
    /// 角色控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    //[Authorize]
    public class RoleController : ControllerBase
    {
        private readonly IMediator mediator;

        public RoleController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult<int>> AddRole(AddRoleCommand request)
        {
            var userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var userName=HttpContext.User.FindFirst(ClaimTypes.Name)?.Value;
            var roleName=HttpContext.User.FindFirst(ClaimTypes.Role)?.Value;
            var customValue=HttpContext.User.FindFirst("CustomClaimType")?.Value;
            var key=HttpContext.User.FindFirst("key")?.Value;

            return mediator.Send(request);
        }
        /// <summary>
        /// 获取角色
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiPaging<RoleDTO>> ShowRole([FromQuery]ShowRoleCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="request"></param>
        [HttpGet]
        public Task<ApiResult<int>> DelRole([FromQuery] DelRoleCommand request)
        {
            return mediator.Send(request);
        }
        [HttpPost]
        public Task<ApiResult<int>> UpdateRole(UpdateRoleCommand request)
        {
            return mediator.Send(request);
        }
    }
}
